package com.alex.keywordtool;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;

public class KeywordParser {

	public void parse(String file, String encoding, Collection<String> results, KeywordFilter filter) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding), 0x1000000);
		String line = null;

		int n = 0;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				continue;
			}
			Keyword keyword = Keyword.parse(line);
			if (filter == null || filter.filter(keyword)) {
				results.add(keyword.getKeyword());
			}
			n++;

			if (n % 100000 == 0) {
				System.out.println(n + " - " + results.size());
			}
		}
		reader.close();
	}

}
